package com.yangqi.ThreadDemo;

/**
 * setName  设置线程的名称
 * getName  获取线程的名称
 * start   启动线程
 * setPriority   设置线程的优先级
 * getPriority   获取线程的优先级
 * sleep   休眠
 * interrupt  中断线程，一般用于休眠线程的唤醒
 * yield 线程的礼让
 * join 线程的插队
 */
public class Thread01 {
    public static void main(String[] args) {
        Cat cat = new Cat();
        cat.start(); //启动线程、
        System.out.println("主线程继续执行" + Thread.currentThread().getName());
        for (int i = 0; i < 10; i++) {
            System.out.println("main" + i);
        }
    }

}

//继承Thread,创建线程
class Cat extends Thread {
    int times = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println("我是小猫咪" + (++times));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (times == 8) {
                break;  //循环结束线程结束
            }
        }
    }
}
